//
//  SDDynamicManager.m
//  SDDataTest
//
//  Created by sodao on 12-9-27.
//  Copyright (c) 2012年 sodao. All rights reserved.
//

#import "SDDynamicManager.h"
#import "SDNetOperation.h"
#import "SDModel.h"

@implementation SDDynamicManager
@synthesize mainDynamic;

-(id)init{
    self = [super init];
    if (!!self) {
        self.mainDynamic = [[SDPageDataPool alloc] initWithArray:nil
                                                       pageIndex:0
                                                        lastDate:nil
                                                            name:@"dynamicCol"];
        jsonParser = [[SBJsonParser alloc] init];
    }
    return self;
}

-(void)getMoreDynamic{
    
    int pageNum = self.mainDynamic.pageIndex;
    int pageSize = self.mainDynamic.pageSize;
    int cmtPageSize = 30;
    int favourPageSize = 10;
    int guanzhuPageSize = 5;
    int zanPageSize = 8;
    NSMutableDictionary* getParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:pageNum],@"pageNum",[NSNumber numberWithInt:pageSize],@"pageSize",[NSNumber numberWithInt:cmtPageSize],@"cmtPagesize",[NSNumber numberWithInt:favourPageSize],@"favourPagesize",[NSNumber numberWithInt:guanzhuPageSize],@"guanzhuPagesize",[NSNumber numberWithInt:zanPageSize],@"zanPagesize",nil];
    NSString* maxdid = nil;
    if (mainDynamic.lastObject!=nil) {
        maxdid = ((Dynamic*)mainDynamic.lastObject).dynamicID;
        [getParams setObject:maxdid forKey:@"maxdid"];
    }
    [[SDNetOperation shareInstance] sendRequestByName:@"dynamicCol"
                                             getParam:getParams
                                            postParam:nil
                                            restParam:nil
                                             postType:0
                                                token:@"Zr3l6VC3YXED_O5ZmNuJ_w2"
                                             deviceID:@""
                                        responseBlock:^(NSString *responseString) {
                                            NSLog(@"%@",responseString);
                                            NSDictionary* dic = [jsonParser objectWithString:responseString];
                                            if ([[dic objectForKey:@"status"] intValue] == 0) {
                                                
                                            }else{
                                                NSArray* result = [dic objectForKey:@"result"];
                                                if ((![result isKindOfClass:[NSNull class]]) && result != nil) {
                                                    for (NSDictionary* dynamictimeDic in result) {
                                                        int dynamicType = [[dynamictimeDic objectForKey:@"dynamictype"] intValue];
                                                        if (dynamicType == 1) {
                                                            [[mainDynamic pageValueArray] addObject:[[Show alloc] initWithDictionary:dynamictimeDic]];
                                                        }else if(dynamicType == 2){
                                                            [[mainDynamic pageValueArray] addObject:[[Attention alloc ] initWithDictionary:dynamictimeDic]];
                                                        }else if(dynamicType == 3){
                                                            [[mainDynamic pageValueArray] addObject:[[Prase alloc] initWithDictionary:dynamictimeDic]];
                                                        }
                                                    }
                                                }else{
                                                    
                                                }
                                            }
                                        }
                                            failBlock:^(NSString *responseString, NSError *error) {
   
                                        }];
}



@end
